<?php
	class connection{
		protected $ip = "193.226.40.143:3306";
		protected $username = "duna25";
		protected $password = "kekdunakeringo";
		protected $dbname = "duna25";
		function connect(&$con,&$succes){
		//host es username password megadasa
			$conn = mysql_connect($this->ip,$this->username,$this->password);
			if (!$conn){
				//ha sikertelen hibauzenettel lepunk vissza
				$con = "Connection failed to server!";
				$succes = false;
			}
			else{
				//kulonben kapsolodunk az adatbazisra 
				$conn=mysql_select_db($this->dbname);
				if (!$conn){//ha nem letezik uzenetet kuldunk vissza
					$con = "The database doesn't exist!";
					$succes = false;
				}
				else{
					//kulonben sikeruzenetet
					$succes = true;
				}
			}
		}
	}
	function generatelistint($x,$db){
		$list="";
		$i=0;
		while ($i<$db){
			if ($i+1<$db)
				$list=$list."$x[$i],";
			else
				$list=$list."$x[$i]";
			$i++;
		}
		return $list;
	}
	function generateliststr($x,$db){
		$list="\"";
		$i=0;
		while ($i<$db){
			if ($i+1<$db)
				$list=$list."$x[$i]\",\"";
			else
				$list=$list."$x[$i]\"";
			$i++;
		}
		return $list;
	}
	class users{	
		public $username;
		protected $password;
		protected $email;
		public $fullname;
		public $right;
		function __construct(){
			$this->username = "";
			$this->password = "";
			$this->email = "";
			$this->fullname = "";
		}
		function set_user($usernamep,$passwordp,$emailp,$fullnamep,$rightp){
			$this->username = $usernamep;
			$this->password = $passwordp;
			$this->email = $emailp;
			$this->fullname = $fullnamep;
			$this->right = $rightp;
			
		}
		public function set_username($usernamep){
			$this->username=$usernamep;
		}
		public function set_password($passwordp){
			$this->password=$passwordp;
		}
		public function set_right($rightp){
			$this->right = $rightp;
		}
		//ellenorizzuk hogy a parameterben megadott felhasznalo letezik-e vagy sem
		public function user_exists($un){
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			//ellenorizzuk hogy parameterben megadott felhasznalonev  van-e az ab-ben
			$query="SELECT COUNT(*) FROM Users WHERE Username='$un'";
			$result=mysql_query($query);
			$count=mysql_fetch_array($result);
			if ($count[0]>0)
			//ha van akkor true
				return true;
			else
			//kulonben false-t kuldunk vissza
				return false;
		}
		//ellenorizzuk hogy a felhasznalonev es jelszo parositas helyes-e vagy sem
		public function user_check(&$ok){
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			//ab-bol lekerjuk hogy letezik-e ilyen felhasznalonev-jelszo parositas
			$query="SELECT COUNT(*) FROM Users WHERE Username='$this->username' AND Password='$this->password'";
			$result=mysql_query($query);
			$count=mysql_fetch_array($result);
			if ($count[0]>0){
			//ha igen true-t kuldunk vissza az ok parameterben
				$ok = true;
			}
			else
			//kulonben falset-t
				$ok = false;
		}
		//ab-bol lekerjuk  a parameterben megadott felhasznalonev jogosultsagat
		public function user_right(){
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			//ellenorizzuk hogy a felhasznalonev letezik-e vagy sem eloszor
			//ha letezik akkor lekerjuk a jogat es vissszakuldjuk a jogat
			if ($this->user_exists($this->username)>0){
				$query="SELECT Jog FROM Users WHERE Username='$this->username'";
				$result=mysql_query($query);
				$count=mysql_fetch_array($result);
				return $count[0];
			}
			else
			//kulonben error uzenetet kuldunk vissza
				return "error";
		}
		//a parameterben megadott informaciokkal hozzaadjuk az adatbazishoz a felhasznalot
		public function insertuserdb(){
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			//ellenorizzuk hogy a felhasznalonev foglalt-e vagy sem
			if ($this->user_exists($this->username)){
			//ha foglalt ebben az esetben hibaval lepunk vissza mivel nem lehet ket egyezo felhasznalonev az ab-ben
				return false;
			}
			else{
				//ha nem foglalt hozzaadjuk az ab-hez es sikert kuldve vissza
				//titkositjuk a jelszot majd elmentjuk az adatbazisba
				$this->password=sha1($this->password);
				mysql_query("INSERT INTO Users(Username,Password,Email,FullName,Jog) VALUES('$this->username','$this->password','$this->email','$this->fullname','$this->right')");
				return true;
			}
		}
		
		//parameterben megadott felhasznalonevu felhasznalo aktivitasait toroljuk es a felhasznalot is az ab-bol
		public function deleteuserdb(){
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			$tmpclass = new users;
			//ellenorizzuk hogy letezik-e ilyen felhasznalo
			if ($tmpclass->user_exists($this->username)){
				//ha igen akkor toroljuk siker uzenetet visszakuldve
				mysql_query("DELETE FROM Activity_Calendar WHERE Username='$this->username'");
				mysql_query("DELETE FROM Users WHERE Username='$this->username'");
				return true;
			}
			else{
				//kulonben false-t kuldve vissza
				return false;
			}
		}
		
		//parameteren keresztul visszakuldunk egy felhasznalonev teljes nev listat, egy listat a usernam-el,
		//es a felhasznalok szamat
		public function getuserlistdb(&$unl,&$nml,&$db,&$un){
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			//lekerjuk a felhasznalonev es teljes nev listat az ab-bol
			$query="SELECT DISTINCT Username,FullName
					FROM Users";
			$result = mysql_query($query);
			$db = mysql_num_rows($result);
			$i=0;
			while ($i<$db){
			//keszitunk javascript szintaxisu listat, es username listat kulon is visszakuldjuk
				$un[$i]=mysql_result($result,$i,"Username");
				$nm[$i]=mysql_result($result,$i,"FullName");
				$i++;
			}
			$unl = generateliststr($un,$db);
			$nml = generateliststr($nm,$db);
		}
		//a parameterben megadott projekt azonosito altal lekerjuk a felhasznalonev es teljes nevet 
		//azokra a felhasznalokra akik az adott projekten dolgoztak
		public function getuserwithprojectlistdb($projectid,&$unl,&$nml,&$db,&$un){
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
				//lekerjuk a listat az ab-bol
			$query="SELECT DISTINCT Users.Username,FullName
					FROM Users,Activity_Calendar
					WHERE Activity_Calendar.Username=Users.Username AND Activity_Calendar.Project_ID='$projectid'";
			$result = mysql_query($query);
			$db = mysql_num_rows($result);
			$i=0;
			while ($i<$db){
			//kigeneraljuk username,fullname javascript listat, username listat es a felhasznalok szamat
				$un[$i]=mysql_result($result,$i,"Username");
				$nm[$i]=mysql_result($result,$i,"FullName");
				$i++;
			}
			$unl = generateliststr($un,$db);
			$nml = generateliststr($nm,$db);
		}
		//parameterben megadott felhasznalonak a jogat atallitjuk adminra ha meg nem admin
		//ha admin hibat jelentunk
		public function adminsetdb(){
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			//ha az adott felhasznalo joga meg nem admin akkor admin-ra allitjuk
			$query="SELECT Jog
					FROM Users
					WHERE Username = '$this->username'";
			$result = mysql_query($query);
			$jog = mysql_fetch_array($result);
			if ($jog[0] != 'admin'){
				//adminra allitjuk ha meg nem admin es sikeres uzenetet kuldunk vissza
				$query="UPDATE Users SET Jog='admin' WHERE Username = '$this->username'";
				mysql_query($query);
				return true;
			}
			else{
				//ha mar admin jelezzuk
				return false;
			}
		}
	}
	class projects{
		public $projectname;
		public $projectid;
		function __construct(){
			$this->projectname = "";
			$this->projectid = "";
		}
		function __construct1($projectnamep,$projectidp){
			$this->projectname = $projectnamep;
			$this->projectid = $projectidp;
		}
		public function set_projectname($projectnamep){
			$this->projectname = $projectnamep;
		}
		public function set_projectid($projectidp){
			$this->projectid = $projectidp;
		}
		//a parameterben megadott felhasznalo altal dolgozott projektek nevet, azonositojat es szamat kuldi vissza
		public function getprojectwithuserlistdb($userid,&$projectlist,&$pidlist,&$db){
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			//kapcsolodas az adatbazishoz
			if (!$succes)
				die ("$con");
			//lekeres az adatbazisbol
			$query="SELECT DISTINCT Projects.Name,Projects.ID
					FROM Projects,Activity_Calendar
					WHERE Activity_Calendar.Project_ID=Projects.ID AND Activity_Calendar.Username='$userid'";
			$result = mysql_query($query);
			$db = mysql_num_rows($result);
			$i=0;
			//lista kivetele az eredmenyhalmazbol majd tovabitas
			while ($i<$db){
				$pname[$i] = mysql_result($result,$i,"Name");
				$pidlist[$i] = mysql_result($result,$i,"ID");
				$i++;
			}
			$projectlist = generateliststr($pname,$db);
		}
		//visszaadja a parameterben az osszes projekt nevet es azonositojat
		public function getprojectlistdb(&$nmp,&$id,&$pid){
		//kapcsolodas az adatbazishoz
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			//lekerdezes az adatbazisbol
			$query="SELECT Name,ID
					FROM Projects";
			$result = mysql_query($query);
			$db = mysql_num_rows($result);
			$i=0;
			//kivesszuk az eredmenyt listaba majd tovabitas
			while ($i<$db){
				$pname[$i] = mysql_result($result,$i,"Name");
				$pid[$i] = mysql_result($result,$i,"ID");
				$i++;
			}
			$nmp = generateliststr($pname,$db);	
			$id = generateliststr($pid,$db);
		}
		//visszakuldi a projektek szamat
		public function getcountprojectdb(){
		//adatbazisra kapcsolodas
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
		//lekerdezes az adatbazisbol
			$query="SELECT COUNT(*)
					FROM Projects";
			$result = mysql_query($query);
			$db = mysql_fetch_array($result);
			return $db[0];
		}
		//a parameterben megadott projektet hozzaadja az adatbazishoz ha meg nem letezik az ab-ben
		public function insertprojectdb(){
		//kapcsolodas az adatbazishoz
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			//megnezzuk hogy letezik-e ilyen projektnev
			$query="SELECT COUNT(*) FROM Projects WHERE Name='$this->projectname'";
			$result=mysql_query($query);
			$count=mysql_fetch_array($result);
			if ($count[0]>0){
				//ha igen akkor kiirjuk hogy mar letezik a projekt
				return false;
			}
			else{
				//ha nem akkor beszurjuk
				mysql_query("INSERT INTO Projects(Name) Values('$this->projectname');");
				return true;
			}
		}
		//parameterben megadott azonositoval ellatott projektet torli az adatbazisbol		
		public function deleteprojectdb(){
		//kapcsolodas az adatbazishoz
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			//adatbazisbol lekerdezzuk hogy van-e ilyen projekt
			$query="SELECT COUNT(*) FROM Projects WHERE ID='$this->projectid'";
			$result=mysql_query($query);
			$count=mysql_fetch_array($result);
			//ha igen akkor toroljuk
			if ($count[0]>0){
				//kitoroljuk az adott projekten az aktivitasokat is es a projektet is
				mysql_query("DELETE FROM Activity_Calendar WHERE Project_ID='$this->projectid'");
				mysql_query("DELETE FROM Projects WHERE ID='$this->projectid'");
				return true;
			}
			else{
				return false;
			}
		}
	}
	class activityhours{
		public $username;
		public $projectid;
		public $activityid;
		public $hour;
		function __construct(){
			$this->username = "";
			$this->projectid = "";
			$this->activityid = "";
			$this->hour = "";
		}
		function set_activityhour($usernamep,$projectidp,$activityidp,$nrhourp){
			$this->username = $usernamep;
			$this->projectid = $projectidp;
			$this->activityid = $activityidp;
			$this->hour = $nrhourp;
		}
		public function set_username($usernamep){
			$this->username = $usernamep;
		}
		public function set_projectid($projectidp){
			$this->projectid = $projectidp;
		}
		//beszurja az adatbazisba a arameterben megadott activityt, az adott 2 datum koze, es visszakuld
		//kodot az eredmennyel, 0 ha nincs hiba, -1 eseten hiba tortent, tobb mint 0 eseten tulcsordulas
		public function insertactivityhourdb($start,$end,$type,$weekend,&$sum){
			function isWeekend($weekDay){
				//ha az adott nap hetvege akkor true-t kuldunk vissza kulonben false-t
				return ($weekDay == 0 || $weekDay == 6);
			}
			function networkdays($s, $e, $holidays = array()) {
				//megcsereljuk ha veletlenul rosszul lett megadva a start/end datum   
				if ($s > $e)
					return networkdays($e, $s, $holidays);
				//meghatarozzuk a napnak a szamat a ket datumnak
				$sd = date("N", $s);
				$ed = date("N", $e);
				// hetek szamat
				$w = floor(($e - $s)/(86400*7));    //elosszuk hettel a kulonbseget a ket datum kozott 86400 az nappa alakitasi alak
				if ($ed >= $sd) { $w--; }    //csokkentjuk a hetek szamat ha a vegso datum kisebb vagy egyenlo mint a kezdet
				// kiszamoljuk a munkanapokat
				$nwd = max(6 - $sd, 0);   //ha a szombat vagy vasarnappal kezd zerot add kulonben 6-kezdeti nap szamat
				$nwd += min($ed, 5); //ha a vege szombat vagy vasarnap 5-ot add hozza vagy a vegso nap szamat
				$nwd += $w * 5;       //5-ot hozzaad minden het eseteben
				//ha vannak kulonleges szabadsagok es azok nem szombat vagy vasarnap azokat is levonja 
				//ezeket lehet hozzaadni ha arrol van szo
				foreach ($holidays as $h) {
					$h = strtotime($h);
					if ($h > $s && $h < $e && date("N", $h) < 6)
						$nwd--;
				}
				return $nwd;
			}
			//datumok idore atalakitasa
			$start = strtotime("$start");
			$end = strtotime("$end");
			//kapcoslodas az adatbazisra
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
				//elosszuk vagy sem az orakat ahhoz merten hogy lett kijelolve a felhasznalo altal
				//hetvegeket beleszamolva vagy nem
			if ($type == "on")
				if ($weekend=="off"){
					$holidays = array();//kulonleges szabadsagnapok esetunkben nincsenek csak a hetvegek
					//elosztjuk a hetkoznapok szamaval
					$this->hour=($this->hour)/networkdays($start, $end, $holidays);
				}
				else{
					$sd = date("j", $start);
					$ed = date("j", $end);
					//elosztjuk a hetkoznapok es hetvegek szamaval egyutt
					$this->hour=($this->hour)/($ed-$sd+1);
				}
			$sum=0;
			//vegigmegyunk a kezdeti datumtol a vegdatumig naponkent
			for ( $i = $start; $i <= $end; $i += 86400 ){
				$datum=date("Y-m-d",$i);
				$query = "SELECT SUM(Nr_Hour) FROM Activity_Calendar WHERE Datum > '$datum 00:00:00' AND Datum < '$datum 23:59:59' AND Username='$this->username'";
				$result = mysql_query($query);
				$nrhourall = mysql_fetch_array($result);
				//megnezzuk hogy letezik-e mar ezen a napon ez az activity ettol a projektrol mivel akkor csak hozzaadjuk 
				$query = "SELECT Nr_Hour FROM Activity_Calendar WHERE Activity_ID='$this->activityid' AND Datum > '$datum 00:00:00' AND Datum < '$datum 23:59:59' AND Username='$this->username' AND Project_ID='$this->projectid'";
				$result = mysql_query($query);
				$nrhoura = mysql_fetch_array($result);
				//ha letezik az adott aktivitas hozzaadjuk az oraszamot 
				//ha tul haladna a 24 orat lementjuk a tulcsordulast es hibanal kiirjuk
				
				if ($nrhourall[0]+$this->hour > 24){
					//ha az adott nap aktivitasa es a beszurando meghaladja a 24 orat akkor kivonjuk a tulcsordulast es hozzaadjuk
					//a maradekot az adatbazishoz
					$sum = $this->hour;
					$nhour=0;
					if ($nrhoura[0]>0){
					//ha mar letezik az adott aktivitas akkor hozzaadjuk a nem tulcsordult reszt a letezo aktivitashoz
						$nhour=$nrhoura[0]+$this->hour-($nrhourall[0]+$this->hour-24);
						$sum = $sum + $this->hour - $nhour;
					}
					else{
					//ha nem letezik akkor a nem tulcsordult reszt letrehozzuk
						$nhour=$this->hour-($nrhourall[0]+$this->hour-24);
						$sum = $sum + $this->hour - $nhour;
					}
				}
				else{
					if ($nrhoura[0]>0)
					//ha letezik az adott aktivitas es nincs tulcsordulva a beszurni valo akkor hozzaadjuk 
					//a letezohoz a teljes beszursni kivant orat
						$nhour=$nrhoura[0]+$this->hour;
					else
					//ha nem letezik es nincs tulcsordulas teljes beszurni kivant orat hozzaadjuk az adatbazishoz
						$nhour=$this->hour;
				}
				if ($weekend == "off"){
					if ($nrhoura[0]>0){	//ha letezik az aktivitas akkor hozzaadjuk
						$weekday=date("w",$i);
						if (!isWeekend($weekday)){
							//ha nincs hetvege akkor betesszuk ha nem akkor hozzaadjuk
							$query = "UPDATE Activity_Calendar SET Nr_Hour='$nhour' WHERE Activity_ID='$this->activityid' AND Datum > '$datum 00:00:00' AND Datum < '$datum 23:59:59' AND Username='$this->username' AND Project_ID='$this->projectid'";
							mysql_query($query) or die("Update error");
						}
					}
					else{
						if ($nhour>0){//ha nem letezik meg az aktivitas egy uj tevekenysegkent illesztjuk be
							$weekday=date("w",$i);
							if (!isWeekend($weekday)){
								//ha nem hetvege akkor mentjuk a regisztralast
								$query = "INSERT INTO Activity_Calendar(Username,Project_ID,Activity_ID,Datum,Nr_Hour) VALUES('$this->username','$this->projectid','$this->activityid','$datum 09:00:00','$nhour')";
								mysql_query($query);
							}
						}
					}
				}else{
					if ($nrhoura[0]>0){	//ha letezik az aktivitas akkor hozzaadjuk
						$query = "UPDATE Activity_Calendar SET Nr_Hour='$nhour' WHERE Activity_ID='$this->activityid' AND Datum > '$datum 00:00:00' AND Datum < '$datum 23:59:59' AND Username='$this->username' AND Project_ID='$this->projectid'";
						mysql_query($query) or die("");
					}else{
						if ($nhour>0){//ha nem letezik meg az aktivitas egy uj tevekenysegkent illesztjuk be
							$query = "INSERT INTO Activity_Calendar(Username,Project_ID,Activity_ID,Datum,Nr_Hour) VALUES('$this->username','$this->projectid','$this->activityid','$datum 09:00:00','$nhour')";
							mysql_query($query);
						}									
					}
				}
			}
		}
		
		//parameterben megadott adattal rendelkezo aktivitast toroljuk az adatbazisbol
		public function deleteactivityhourdb($projectactivityid,$start,$end){
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			//elvalasztjuk a parameterbol kapott projektnev-activity-t egy tombbe
			$pnameactivity = explode("-",$projectactivityid);
			//kapcsolodunk az adatbazisra
			if (!$succes)
				die ("$con");
			//toroljuk az adatbazisbol
			$query="DELETE FROM Activity_Calendar WHERE Project_ID='$pnameactivity[0]' AND Datum>='$start 00:00:00' AND Datum<='$end 23:59:59' AND Activity_ID='$pnameactivity[1]' AND Username='$this->username'";
			mysql_query($query);
		}
		//parameterben megadott azonositoju projektre visszakuldjuk az ossznapszamot
		public function getallsumactivitydaydb(&$workday){
			//kapcsolodas az ab-re
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			//lekerjuk a projekt kezdetet
			$query="SELECT MIN(Datum)
					FROM Activity_Calendar
					WHERE Project_ID = '$this->projectid'";
			$result = mysql_query($query);
			$min = mysql_fetch_array($result);
			//projekt veget
			$query="SELECT MAX(Datum)
					FROM Activity_Calendar
					WHERE Project_ID = '$this->projectid'";
			$result = mysql_query($query);
			$max = mysql_fetch_array($result);
			$min = strtotime("$min[0]");
			$max = strtotime("$max[0]");
			//visszakuldjuk a 2 kozotti kulonbseget
			$sub=$max-$min;
			$workday=floor(($sub/86400))+1;
			if ($workday == null)
				$workday = 0;
		}
		//parameterben megadott azonositoju projektre visszakuldjuk az osszoraszamot
		public function getallsumactivityhourdb(&$workhour){
		//kapcsolodas az ab-re
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			//lekerjuk az dolgozott orak osszeget
			$query="SELECT SUM(Nr_Hour)
					FROM Activity_Calendar
					WHERE Project_ID = '$this->projectid'";
			$result = mysql_query($query);
			$workhourl = mysql_fetch_array($result);
			$workhour=$workhourl[0];
			if ($workhour == null)
				$workhour = 0;
				//es visszakuldjuk
		}
		//parameterben megadott felhasznalonevre lekerjuk a pramaeterben megadott projekten dolgzott napjait
		public function getsumactivitydaydb(&$workday){
			//adatbazisra kapcsolodas
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			//lekerjuk a projekt kezdetet
			$query="SELECT MIN(Datum)
					FROM Activity_Calendar
					WHERE Project_ID = '$this->projectid' AND Username='$this->username'";
			$result = mysql_query($query);
			$min = mysql_fetch_array($result);
			//lekerjuk a projekt veget
			$query="SELECT MAX(Datum)
					FROM Activity_Calendar
					WHERE Project_ID = '$this->projectid' AND Username='$this->username'";
			$result = mysql_query($query);
			$max = mysql_fetch_array($result);
			$min = strtotime("$min[0]");
			$max = strtotime("$max[0]");
			$sub=$max-$min;
			//e ketto kozotti kulonseget pedig visszakuldjuk
			$workday=floor(($sub/86400))+1;
			if ($workday == null)
				$workday = 0;
		}
		//parameterben megadott felhasznalonevre lekerjuk a pramaeterben megadott projekten dolgzott orait
		public function getsumactivityhourdb(&$workhour){
			//kapcsolodas az ab-re
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			//lekerjuk az orak osszeget az ab-bol
			$query="SELECT SUM(Nr_Hour)
					FROM Activity_Calendar
					WHERE Project_ID = '$this->projectid' AND Username='$this->username'";
			$result = mysql_query($query);
			$workhourl = mysql_fetch_array($result);
			$workhour=$workhourl[0];
			if ($workhour == null)
				$workhour = 0;
			//es visszkuldjuk
		}
		//parameterben megadott felhaszalonevre visszakuldjuk a listat a parameterben
		//megadott datumok kozott a projektek nevevl, activity-k nevevel es a rajtuk dolgozott orakkal
		public function getactivityhourlistdb($sd,$ed,&$list1t,&$list2t){
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			//adatbazisra kapcsolodas
			if (!$succes)
				die ("$con");
				//lekeres az adatbazisbol
			$query="SELECT Activitys.Name AS AName,Projects.Name AS PName,Activitys.ID AS AID,Projects.ID AS PID,Nr_Hour
					FROM Activitys,Projects,Activity_Calendar
					WHERE Activity_ID = Activitys.ID AND Project_ID=Projects.ID AND Username='$this->username' AND Datum >= '$sd' AND Datum <= '$ed'";
			$result = mysql_query($query);
			$db = mysql_num_rows($result);
			$i=0;
			$list1t="";
			$list2t="";
			//eredmenyt atalakitjuk listakra
			while ($i<$db){
				$pname = mysql_result($result,$i,"PName");
				$aname = mysql_result($result,$i,"AName");
				$pid = mysql_result($result,$i,"PID");
				$aid = mysql_result($result,$i,"AID");
				$hour = mysql_result($result,$i,"Nr_Hour");
				$i++;
				$list1t = $list1t."'$pname-$aname-$hour hour'";
				$list2t = $list2t."'$pid-$aid'";
				if ($i<$db){$list1t=$list1t.",";$list2t=$list2t.",";}
			}
			//listakat pedig visszkauldjuk
		}
		//parameterben megadott felhasznalonevre visszakuldjuk a listat
		//a parameterben megadott datumintervallumbol  az aktivitasok es projektek listajaval
		//a honapba kilistazando formaval
		public function getactivityhourlistdbhtml($sd,$ed,&$list){
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			//adatbazisra kapcsolodas
			if (!$succes)
				die ("$con");
				//lekeres az adatbazisbol
			$query="SELECT Activitys.Name AS AName,Projects.Name AS PName,Activitys.ID AS AID,Projects.ID AS PID,Nr_Hour
					FROM Activitys,Projects,Activity_Calendar
					WHERE Activity_ID = Activitys.ID AND Project_ID=Projects.ID AND Username='$this->username' AND Datum >= '$sd' AND Datum <= '$ed'";
			$result = mysql_query($query);
			$db = mysql_num_rows($result);
			$i=0;
			//atvesszuk lsitaba az eredmenyeket
			while ($i<$db){
				$pname = mysql_result($result,$i,"PName");
				$aname = mysql_result($result,$i,"AName");
				$pid = mysql_result($result,$i,"PID");
				$aid = mysql_result($result,$i,"AID");
				$hour = mysql_result($result,$i,"Nr_Hour");
				$i++;
				$list = $list."<p>$pname-$aname-$hour hour</p><br>";
			}
			//majd tovabbitjuk a listat
		}	
	}
	class activitys{
		public $activityname;
		public $activityid;
		public function set_activityname($activitynamep){
			$this->activityname=$activitynamep;
		}
		public function set_activityid($activityidp){
			$this->activityid=$activityidp;
		}
		function __construct(){
			$this->activityname = "";
			$this->activityid = "";
		}
		function __construct1($activitynamep,$activityidp){
			$this->activityname = $activitynamep;
			$this->activityid = $activityidp;
		}
		//parameterben megadott aktivitas nevet hozzaadja az adatbazishoz ha meg nincs benne az ab-ben
		public function insertactivitydb(){
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			//megnezzuk hogy letezik-e ilyen projektnev
			$query="SELECT COUNT(*) FROM Activitys WHERE Name='$this->activityname'";
			$result=mysql_query($query);
			$count=mysql_fetch_array($result);
			if ($count[0]>0){
				//ha igen akkor kiirjuk hogy mar letezik a projekt
				return false;
			}
			else{
				//ha nem akkor beszurjuk
				mysql_query("INSERT INTO Activitys(Name) Values('$this->activityname');");
				return true;
			}
		}
		//a parameterben visszakuldi az aktivitasok nevet es azonositojat tartalmazo listakat
		public function getactivitylistdb(&$nmp,&$aid){
			//listageneralo fuggveny
			//adatbazisra kapcsolodas
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
				//lekerdezes az adatbazisbol
			$query="SELECT *
					FROM Activitys";
			$result = mysql_query($query);
			$db = mysql_num_rows($result);
			$i=0;
			//eredmeny atvetele a listakba
			while ($i<$db){
				$a[$i]=mysql_result($result,$i,"Name");
				$b[$i]=mysql_result($result,$i,"ID");
				$i++;
			}
			//majd javascriptes szintaxisu listara alakitas
			$nmp = generateliststr($a,$i);
			$aid = generateliststr($b,$i);
		}
		//parameterben megadott azonositoval renelkezo activity-t torli az adatbazisbol
		public function deleteactivitydb(){
			$tmpclass = new connection;
			$tmpclass->connect($con,$succes);
			if (!$succes)
				die ("$con");
			//megnezzuk hogy letezik-e ilyen projektnev
			$query="SELECT COUNT(*) FROM Activitys WHERE ID='$this->activityid'";
			$result=mysql_query($query);
			$count=mysql_fetch_array($result);
			if ($count[0]>0){
				//ha igen akkor kiirjuk hogy mar letezik a projekt
				mysql_query("DELETE FROM Activity_Calendar WHERE Activity_ID='$this->activityid'");
				mysql_query("DELETE FROM Activitys WHERE ID='$this->activityid'");
				return true;
			}
			else{
				//ha nem akkor beszurjuk
				return false;
			}
		}
	}	
?>